import {ApplicationConfig} from '@angular/core';
import {provideTranslateService} from '@ngx-translate/core';
import {provideTranslateHttpLoader} from '@ngx-translate/http-loader';
import {provideHttpClient, withInterceptors} from '@angular/common/http';
import {provideStore} from '@ngrx/store';
import {provideStoreDevtools} from '@ngrx/store-devtools';
import {reducers, metaReducers} from './cne.state';
import {AuthService} from './auth/auth.service';
import {globalHttpInterceptor} from './interceptors/global-http-interceptor';
import {MockDataService} from '@shared/mock/mock-data.service';
import {InMemoryWebApiModule} from 'angular-in-memory-web-api';
import { environment as env } from '@env/environment';
/**
 * 核心配置
 * 包含多语言、认证、状态管理、Mock 服务等核心功能配置
 */
export const cneConfig: ApplicationConfig = {
  providers: [
    // ngx-translate
    provideTranslateService({
      loader: provideTranslateHttpLoader({
        prefix: '/assets/locale/locale-',
        suffix: '.json'
      }),
      fallbackLang: 'zh_CN',
      lang: 'zh_CN'
    }),

    // ngrx
    provideStore(reducers, {
      metaReducers: metaReducers
    }),

    // ngrx devtools (仅开发环境启用)
    ...(!env.production ? [
      provideStoreDevtools({
        maxAge: 25, // 保留最近 25 个历史记录
        logOnly: false, // 允许使用浏览器的 Console API
        connectInZone: true // 在 NgZone 中连接
      })
    ] : []),

    // http 客户端配置
    provideHttpClient(
      withInterceptors([globalHttpInterceptor])
    ),

    // 认证服务
    AuthService,

    // Mock 数据服务
    ...(env.production ? [] : [
      ...InMemoryWebApiModule.forRoot(MockDataService, {
        delay: 100, // 模拟网络延迟
        passThruUnknownUrl: true, // 允许静态资源通过
        apiBase: '/api/' // API 基础路径
      }).providers || []
    ]),

  ]
};

